<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>redis知识 | 雁过留声</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="#docker运行redis script1docker run -d  --restart&#x3D;always -v &#x2F;root&#x2F;file&#x2F;redis.conf:&#x2F;home&#x2F;redis.conf -p 6379:6379 --name my_redis d4f259423416 redis-server &#x2F;home&#x2F;redis.conf  #设置密码 1修改redis.conf requirepass">
<meta property="og:type" content="article">
<meta property="og:title" content="redis知识">
<meta property="og:url" content="http://yanglf007.gitee.io/blog/2020/05/30/redis%E7%9F%A5%E8%AF%86/index.html">
<meta property="og:site_name" content="雁过留声">
<meta property="og:description" content="#docker运行redis script1docker run -d  --restart&#x3D;always -v &#x2F;root&#x2F;file&#x2F;redis.conf:&#x2F;home&#x2F;redis.conf -p 6379:6379 --name my_redis d4f259423416 redis-server &#x2F;home&#x2F;redis.conf  #设置密码 1修改redis.conf requirepass">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2020-05-30T13:59:09.128Z">
<meta property="article:modified_time" content="2020-08-27T13:16:28.237Z">
<meta property="article:author" content="yanglf007">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/blog/atom.xml" title="雁过留声" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

<meta name="generator" content="Hexo 4.2.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog/" id="logo">雁过留声</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/blog/">Home</a>
        
          <a class="main-nav-link" href="/blog/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/blog/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yanglf007.gitee.io/blog"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-redis知识" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/blog/2020/05/30/redis%E7%9F%A5%E8%AF%86/" class="article-date">
  <time datetime="2020-05-30T13:59:09.128Z" itemprop="datePublished">2020-05-30</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      redis知识
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>#docker运行redis</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d  --restart=always -v /root/file/redis.conf:/home/redis.conf -p 6379:6379 --name my_redis d4f259423416 redis-server /home/redis.conf</span><br></pre></td></tr></table></figure>

<p>#设置密码</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">修改redis.conf requirepass tenny     &#x2F;&#x2F;注意，行前不能有空格</span><br></pre></td></tr></table></figure>
<ol>
<li>哨兵模式</li>
</ol>
<p>哨兵模式是一种特殊的模式，首先Redis提供了哨兵的命令，哨兵是一个独立的进程，作为进程，它会独立运行。其原理是哨兵通过发送命令，<br>等待Redis服务器响应，从而监控运行的多个Redis实例</p>
<p>用文字描述一下故障切换（failover）的过程。假设主服务器宕机，哨兵1先检测到这个结果，<br>系统并不会马上进行failover过程，仅仅是哨兵1主观的认为主服务器不可用，这个现象成为主观下线。<br>当后面的哨兵也检测到主服务器不可用，并且数量达到一定值时，那么哨兵之间就会进行一次投票，<br>投票的结果由一个哨兵发起，进行failover操作。切换成功后，就会通过发布订阅模式，让各个哨兵把自己监控的从服务器实现切换主机，<br>这个过程称为客观下线。这样对于客户端而言，一切都是透明的</p>
<p>2,Redis 常见性能问题和解决方案？<br>主库避免开启数据备份，从库可以开启，每秒同步一次<br>主库和重库避免跨机房，在同一局域网内</p>
<ol start="3">
<li>redis主从复制<br>全量复制<br>一. 从服务器通过slaveof 找到主服务器的ip和端口,链接上主服务器<br>二. 从服务器向主服务器发送psync 命令,要求同步数据<br>三. 主服务器收到命令,使用bgsave,异步将内存中的数据写入到磁盘中,同时开启缓存,之后的写命令进入缓存区<br>四. 主服务器向从服务器发送rdb文件,从服务器接受文件,解析并载入内存<br>五. 发送缓冲期数据,从服务器刷新数据</li>
</ol>
<p>部分复制<br>如果因为网络抖动,主从服务器断开链接<br>主服务器 写命令进入复制缓存区<br>从服务器执行sync命令,带上run_id 和 off_set<br>主服务器查看off_set是否在缓存区范围之内,如果在,主服务器就会发送continue命令,从偏移量开始同步数据</p>
<p>offset 在主服务表示已经发送的位置<br>        在从服务器表示已经接受的位置,两个直接就是从服务器需要同步的数据</p>
<p>4.redis原理</p>
<ol start="5">
<li>redis选举</li>
</ol>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yanglf007.gitee.io/blog/2020/05/30/redis%E7%9F%A5%E8%AF%86/" data-id="ckgtnonn1000hm8ulh73f1o6d" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/blog/2020/05/31/arthas%E7%9F%A5%E8%AF%86/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          arthas知识
        
      </div>
    </a>
  
  
    <a href="/blog/2020/05/08/git%E7%9F%A5%E8%AF%86/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">git知识</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/10/">October 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/08/">August 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/07/">July 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/06/">June 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/05/">May 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/04/">April 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog/2020/10/25/%E6%AF%8F%E6%97%A5%E5%AD%A6%E4%B9%A0/">每日学习</a>
          </li>
        
          <li>
            <a href="/blog/2020/10/12/mybatis-plus/">mybatis-plus</a>
          </li>
        
          <li>
            <a href="/blog/2020/08/30/%E7%A7%92%E6%9D%80%E7%B3%BB%E7%BB%9F/">秒杀系统</a>
          </li>
        
          <li>
            <a href="/blog/2020/08/29/elasticsearch%E7%9F%A5%E8%AF%86/">elasticsearch知识</a>
          </li>
        
          <li>
            <a href="/blog/2020/08/28/redis%E9%9D%A2%E8%AF%95/">redis面试</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 yanglf007<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/blog/" class="mobile-nav-link">Home</a>
  
    <a href="/blog/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/blog/fancybox/jquery.fancybox.css">

  
<script src="/blog/fancybox/jquery.fancybox.pack.js"></script>




<script src="/blog/js/script.js"></script>




  </div>
</body>
</html>